package com.cda.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by xiexingbao on 2018/8/21.
 */
public class Serialnumber {
    /**
     * 获取现在时间
     * @return返回字符串格式yyyyMMddHHmmss
     */
    public static String getStringDate() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String dateString = formatter.format(currentTime);
        System.out.println("TIME:::"+dateString);
        return dateString;
    }
    /**
     * 由年月日时分秒+4位随机数
     * 生成13流水号
     * @return
     */
    public static String Getnum13(){
        String t = getStringDate();
        int x=(int)(Math.random()*9000)+1000;
        String serial ="2"+ t + x;
        return serial;
    }

    /**
     * 由年月日时分秒+4位随机数
     * 生成8流水号
     * @return
     */
    public static String Getnum8(){
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("MMdd");
        String dateString = formatter.format(currentTime);
        int x=(int)(Math.random()*900)+1000;
        String serial = "1" + dateString + x;
        return serial;
    }

    //主方法测试
    public static void main(String[] args) {


    }

}
